package titt.util.deploy;

import titt.service.content.Mimes;
import titt.util.Bytes;
import titt.util.JAR;
import titt.util.io.compile.JSCompiler;

public class TITTCache implements Cache {

	private long modified = -1;
	private byte[] val;
	
	@Override
	public boolean isOutdated() {
		return !JAR.get().isJAR() && modified < JSCompiler.TITTlastModifed();
	}
	
	@Override
	public byte[] getValue() {
		return val;
	}
	
	@Override
	public String getMimeType() {
		return Mimes.JAVASCRIPT;
	}

	@Override
	public void update() throws Exception {
		modified = JSCompiler.TITTlastModifed();
		val = Bytes.asBytes(JSCompiler.compileTITT());
	}

}
